package modelo;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class AutoDAO {

	public AutoDAO() {
		super();
	}

	
	public void registrarAuto(Auto auto) {
		String tiraSQL = "INSERT INTO auto "+
		 				 "(aut_pla, aut_ced, aut_mar, aut_mod, aut_ano, aut_color, aut_status) "+
		 				 "VALUES ("+
		 				 "'"+ auto.getAut_pla() + "','"
		 				 + auto.getAut_ced() + "','"
		 				 + auto.getAut_mar() + "','"
		 				 + auto.getAut_mod() + "','"
		 				  + auto.getAut_ano() + "','"
		 				   + auto.getAut_color() + "','"
		 				 + auto.getAut_status() +"')";
		Conexion.ejecutar(tiraSQL);
	}
	
	
	
	public List<Auto> consultarAuto() {
		List<Auto> autos = new ArrayList<Auto>();
		String tiraSQL = "SELECT * FROM auto";
		ResultSet resultSet = Conexion.consultar(tiraSQL);	
		
		try {
			while (resultSet.next()) {
				
				String aut_pla = resultSet.getString("aut_pla");
				String aut_ced = resultSet.getString("aut_ced");
				String aut_mar = resultSet.getString("aut_mar");
				String aut_mod = resultSet.getString("aut_mod");
				String aut_ano = resultSet.getString("aut_ano");
				String aut_color = resultSet.getString("aut_color");
				String aut_status = resultSet.getString("aut_status");
				Auto auto = new Auto (aut_pla, aut_ced, aut_mar, aut_mod, aut_ano, aut_color, aut_status);
				autos.add(auto);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return autos;
	}

	
}
